package com.haois.mp.database.module.offaccounts.controller;

import com.haois.mp.database.commom.enums.MpTypeEnum;
import com.haois.mp.database.module.common.daomain.UserToken;
import com.haois.mp.database.module.common.service.IUserTokenService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * description
 *
 * @author RuiHaoZ on GuangZhou
 * @date 2018/9/5 21:46
 */
@Controller
@RequestMapping("/wxmp/driver")
public class DriverController {
    @Autowired
    private IUserTokenService iUserTokenService;

    @RequestMapping("/vehicle/list")
    public ModelAndView vehicleList() {
        return null;
    }

    @RequestMapping("/driver/list")
    public ModelAndView driverList() {
        return null;
    }


    @RequestMapping("/server")
    public ModelAndView driverServer(String plate) {
        ModelAndView mv = new ModelAndView("/driver/records");
        mv.addObject("plate", plate);
        return mv;
    }

    @RequestMapping("/driver/edit")
    public ModelAndView driverAdd(Integer id) {
        ModelAndView mv = new ModelAndView("/driver/driverEdit");
        mv.addObject("driverId", id);
        return mv;
    }

    @RequestMapping("/vehicle/edit")
    public ModelAndView vehicleAdd(Integer id) {
        ModelAndView mv = new ModelAndView("/driver/vehicleEdit");
        mv.addObject("vehicleId", id);
        return mv;
    }

    @RequestMapping("/vehicle/info")
    public ModelAndView vehicleInfo(Integer id) {
        ModelAndView mv = new ModelAndView("/driver/vehicleInfo");
        mv.addObject("vehicleId", id);
        mv.addObject("memberNum", "memberNum");
        return mv;
    }

    @RequestMapping("/wz/info")
    public ModelAndView wz(Integer id, String memberNum,String share, HttpServletRequest request) {
        ModelAndView mv = new ModelAndView("/driver/wzInfo");
        mv.addObject("wzId", id);
        mv.addObject("share", share);
        if (StringUtils.isNotBlank(memberNum)) {
            mv.addObject("memberNum", memberNum);
        } else {
            String access_token = (String) request.getAttribute("access_token");
            UserToken userToken = iUserTokenService.findByAccessToken(access_token, MpTypeEnum.OFFACCOUNTS.getType());
            if (userToken != null) {
                mv.addObject("memberNum", userToken.getUserId());
            }
        }
        return mv;
    }


    @RequestMapping("/driver/info")
    public ModelAndView driverInfo(Integer id) {
        ModelAndView mv = new ModelAndView("/driver/cardInfo");
        mv.addObject("driverId", id);
        return mv;
    }

    @RequestMapping("/test2")
    public ModelAndView t1(Integer id) {
        ModelAndView mv = new ModelAndView("/driver/transfer");
        mv.addObject("driverId", id);
        return mv;
    }


}
